package ru.tpu.osu.faces.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import ru.tpu.osu.faces.dao.*;

@FacesConverter(forClass=Teacher.class)
public class TeacherConverter implements Converter  {

	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		Teacher t = (Teacher) HibernateUtil.getSession().get(Teacher.class, arg2);
		return t;
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		Teacher t = (Teacher)arg2;
		return t.getUser().getLogin();
	}

}
